#include "stdafx.h"
#include "TransformSystem.h"
#include "EntityDataStore.h"
#include "EntityManager.h"
#include "TransformComponent.h"
#include "GameEngine.h"

namespace ZeEngine
{
    TransformSystem::TransformSystem()
    {
        AddRequiredComponent("TransformComponent");
    }

    TransformSystem::~TransformSystem()
    {
    }

    void TransformSystem::PreUpdate(GameEngine& gameEngine)
    {
        EntityManager& entityManager = gameEngine.GetEntityManager();

        auto stores = entityManager.GetAllEntities();

        for (auto pEntity : stores)
        {
            if (pEntity && IsEntitySupported(pEntity))
            {
                auto pTransformComponent = pEntity->GetComponent<TransformComponent>();

                if (pTransformComponent)
                {
                    pTransformComponent->m_previousPosition = pTransformComponent->GetPosition();
                    pTransformComponent->m_previousScale = pTransformComponent->GetScale();
                    pTransformComponent->m_previousRotation = pTransformComponent->m_rotation;
                }
            }
        }
    }
}